﻿CREATE TABLE [dbo].[Trade] (
    [Id]			INT        IDENTITY (100, 1) NOT NULL,
    [Version]		ROWVERSION NOT NULL,
    [ModifiedBy]	INT        NULL, --zxzx, temp: must be not null
    [ModifiedDt]	DATETIME   NULL, --zxzx, temp: must be not null

	[AccountId]		INT		   NULL CONSTRAINT [FK_Trade_Account] FOREIGN KEY ([AccountId]) REFERENCES [dbo].[Account] ([Id]),
    [InstrumentId]	INT        NULL CONSTRAINT [FK_Trade_Instrument] FOREIGN KEY ([InstrumentId]) REFERENCES [dbo].[Instrument] ([Id]),

	[TradeDt]		DATE       NOT NULL,
	[ValueDt]		DATE       NOT NULL,
	[Activity]		INT		   NOT NULL,
	[Qty]			MONEY      NOT NULL CONSTRAINT [DF_Trade_Qty] DEFAULT(0),
	[Price]			MONEY      NOT NULL CONSTRAINT [DF_Trade_Price] DEFAULT(0),
    [TradeCcy]		CHAR (3)   NULL, --CONSTRAINT [FK_TradeCurrencyInstrument] FOREIGN KEY ([Currency]) REFERENCES [dbo].[CurrencyInstrument] ([Code]),
    [Commission]    MONEY      NOT NULL CONSTRAINT [DF_Trade_Commission] DEFAULT(0),
	
	[Memo]          VARCHAR(255) NULL,

    CONSTRAINT [PK_Trade] PRIMARY KEY CLUSTERED ([Id] ASC)    
);

